package com.itheima.Filter;

import jakarta.servlet.*;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
//@WebFilter(urlPatterns = "/login")
@Slf4j
public class DemoFilter implements Filter {

   //过滤器初始化,web服务器启动时时调用，只执行1次。
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("init 初始化方法......");
    }
    //拦截到请求之后执行，会执行多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("doFilter 拦截到了请求......放行前");

        //放行
        filterChain.doFilter(servletRequest,servletResponse);

        log.info("doFilter 拦截到了请求......放行后");
    }
     //销毁方法，web服务器关闭时调用，只执行1次
    @Override
    public void destroy() {
        log.info("destroy 销毁方法......");
    }
}
